﻿-var entity = ViewData["entity"] as Order
-var notarialactions = ViewData["notarialactions"] as List<NotarialAction>
-var notarialregisters = ViewData.ContainsKey("notarialregisters") ? ViewData["notarialregisters"] as List<NotarialRegister> : null
-var statuses = ViewData["statuses"] as List<Status>
-var marks = ViewData["marks"] as IQueryable<Mark>
-var activenotarius = ViewData["activenotarius"] as NotariusList
-bool popup = ViewData.ContainsKey("popup")
-bool create = (entity.Id == 0)
-var orderperiod = (ViewData.ContainsKey("orderperiod")) ? (int)ViewData["orderperiod"] : 30
-var lockOrderInfo = ViewData.ContainsKey("lockOrderInfo") ? ViewData["lockOrderInfo"] as LockOrderInfo: null
-bool readOnly = ViewData.ContainsKey("readonly")
-bool userCanEditOrder = ViewData.ContainsKey("userCanEditOrder") && ((bool)ViewData["userCanEditOrder"])
-bool clone = ViewData.ContainsKey("clone") 
%form.validate{action="order.ivp/save",method="post",enctype="multipart/form-data"}
  _formfields
  =HTMLHelper.HiddenInput("id",entity.Id)
  =HTMLHelper.HiddenInput("taskid",entity.TaskId)
  =HTMLHelper.HiddenInput("statusid",entity.StatusId, "")
  =HTMLHelper.HiddenInput("createnewaftersave","", "")
  =HTMLHelper.HiddenInput("editmode", !(create || readOnly))
  %select{multiple="true", class="hidden nolink", name="newdoctemplates", id="newdoctemplates"}
  -if (ViewData.ContainsKey("ordercreated"))
    =HTMLHelper.HiddenInput("ordercreated", (int)ViewData["ordercreated"])
  #content{class=(popup ? "popup" : "")}
    .formheader
      %h1
        %table{width="97%"}
          %tr
            %td{width="35%"}
              .floatleft 
                .inline.marginright10
                  %img.icon24{src=(create)?"img/headericons/newtask.gif":"img/headericons/task.gif"}
                .inline
                  =(!create) ? String.Format("Карточка заявки № {0}",entity.Id): "Карточка заявки"
                -if (!create)
                  %a.small.noul{href=String.Format("order.ivp/{0}/{1}{2}", (readOnly) ? "view" : "edit", entity.Id, (popup) ? "?popup=true": "")}
                    %img.paddedbottom5{src="img/arrow_refresh.png", title="Обновить", alt="Обновить"}
                .indent40
                  %span.normal
                    ="Статус: <span class=\"bold\">"  + ((!create) ? entity.Status.Name: "Новая заявка" + "</span>" )
            %td{width="62%"}           
              .floatright
                _buttons
        -if (lockOrderInfo != null)
          .clear
          .lockinfo              
            =String.Format("Заблокировано: {0} {1}", lockOrderInfo.userName, lockOrderInfo.date)   
    _error
    _message
    #orderform.formbody      
      %table{width="98%"}
        %tr
          %td{width="73%"}
            .field 
              %label.required{for="notarialactionid"}Действие:  
              #notarialactionname.padded5.inline
                =(!create || clone) ? entity.NotarialAction.FullName : ""               
              -if (!readOnly)
                %a#linkchangenotarialaction.inline.small.noul{href="#",onclick="return changeNotarialAction(this);",style=(create && !clone) ? "display: none" : ""}="Изменить"
                #changenotarialaction{class=(!create || clone) ? "hidden padded5" : ""}
                  %input#choosenotarialaction.px200
                  %a.noul{href="#",onclick="return selectNotarialAction();"}
                    %img.top{src="img/buttons/browsedialog.gif",title="Выбрать нотариальное действие"}
            =HTMLHelper.HiddenInput("notarialactionid", create && !clone ? "" : entity.NotarialActionId.ToString(), "required")
          %td{width="25%"}
            _taskimport          
      %table{width="100%"}
        %tr
          %td{width="40%"}
            _clients
          %td{width="40%"}
            _responsibles          
      .field
        %label.required{for="description"}Что сделать:
        %div
          %textarea#description.required.width100.autogrow{tabindex="1", name="description", maxlength="2000"}=entity.Description
      -if (!create)
        _history
      .spacer10              
      .field
        -if (create)
          %label{for="comment"}Комментарий:
        %textarea#comment.width100.autogrow{tabindex="2", name="comment",rows="3",maxlength="500"}=String.Empty
        -if (readOnly)
          %div.padded5
            %a#addcomment.noul.small{href="#", onclick=String.Format("return addComment({0});", entity.Id)} Добавить комментарий
      .field
        %label{for="decisionaboutclient"}Принятое решение:              
        %textarea#decisionaboutclient.width100.autogrow{tabindex="3", name="decisionaboutclient", maxlength="2000", disabled=(create) ? "" : "true"}=entity.DecisionAboutClient      
      _attachedfiles      
      .additionalrowswrapper.floatleft.padded5.width60.nopaddingleft
        _additionalrows
        .spacer15
        _deadline
      .costwrapper.floatleft.padded5.width38
        _cost
      .clear
      -if (create)
        =HTMLHelper.HiddenInput("notarialregisterid", (user as User).NotarialRegisterId)
        =HTMLHelper.HiddenInput("markid", marks.First(m => m.Value == 4).Id)
      -else
        %table{width="100%"}
          %tr
            %td{width="62%"}
              .field.padded3                           
                %label.inline.marginright5{for="notarialregisterid"} Номер реестра/Номер записи:
                =HTMLHelper.Select("notarialregisterid", notarialregisters, "name", "id", entity.NotarialRegisterId, "", "", "", false, false, "tabindex=20")
                %label.inline{for="#notarialregisterrow"} /
                %input.number#notarialregisterrow.px40{tabindex="21", name="notarialregisterrow", value=entity.NotarialRegisterRow, min="1"}
            %td
              -if ((user as User).HasPermission("EstimateOrders"))
                .field.padded3
                  %label.inline.marginright5{for="markid"} Оценка заявки:
                  =HTMLHelper.Select("markid", marks, "name", "id", entity.MarkId,  "", "NONE", "", false, false, "tabindex=22")
                  -if (readOnly && !popup)
                    %a.small.noul.indent10{tabindex="22", href="#", onclick="return changeMark(this);"} Изменить
                    %a.small.noul.indent10.hidden{tabindex="22", href="#", onclick="return saveMark(this);"} Сохранить
      -if (activenotarius != null && activenotarius.Items != null && activenotarius.Items.Count() > 0)
        .field.padded3                           
          %label.inline.marginright5{for="activenotariusid"} Нотариус:
          =HTMLHelper.Select("activenotariusid", activenotarius.Items, "name", "id", activenotarius.IOisActive ? 2 : 1, "", "NONE", "", false, false, "tabindex=20")                                                                                   
      =HTMLHelper.HiddenInput("forminvalidmessage", "")
      _paycheckmodal
      _decisioncheckmodal
      _invalidcheckmodal
    .formbottom
      %table{width="99%"}
        %tr
          %td{width="30%"}
            _statusbuttons
          %td{width="70%"}
            .floatright
              _buttons
  #rightmenu
    #doctemplatelistholder
      _doctemplates